#include "head.h"
void dup_test()
{
    int fd1= open("d.txt",O_RDWR|O_CREAT,0666);
    if(fd1<0){
        perror("open file");
        exit(1);
    }
    int fd2 = dup(fd1);
    if(fd2<0){
        perror("dup file");
        exit(1);
    }
    printf("fd1=%d fd2=%d\n",fd1,fd2);
    char *buf = malloc(100);
    memset(buf,0,100);
    int n;
    while( (n=read(fileno(stdin),buf,100))>0){
        write(fd2,buf,n);
    }
    close(fd2);
}